//
//  downLoadCollectionCell2.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/2/25.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "downLoadCollectionCell2.h"
#import "downBtnCell.h"

@interface downLoadCollectionCell2 ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end


@implementation downLoadCollectionCell2
{
    NSArray *chooseArr;//选择的图片数组
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.tiJiao_btn.titleLabel.font = self.titile_lab.font = self.title_lab1.font = AutoLabFont2;
    self.downCollection_view.delegate = self;
    self.downCollection_view.dataSource = self;
    [self.downCollection_view registerNib:[UINib nibWithNibName:@"downBtnCell" bundle:nil] forCellWithReuseIdentifier:@"downBtnCell"];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        return self.pictureArr.count + 2;
    }else{
        return 2;
    }
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((CollectionView_Width - 24)/6, CollectionView_Height/3);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    downBtnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"downBtnCell" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        [cell.delete_btn addTarget:self action:@selector(deletePicture:) forControlEvents:UIControlEventTouchUpInside];
        cell.delete_btn.tag = 3000 + indexPath.row;
        if (indexPath.item == 0) {
            [cell.btn_img setHidden:YES];
            [cell.delete_btn setHidden:YES];
            cell.btn_lab.text = @"作品图片";
        }else if (indexPath.item == 1){
            
            //添加图片
            cell.btn_lab.text = @"";
            [cell.delete_btn setHidden:YES];
            [cell.btn_img setHidden:NO];
            [cell.btn_img setBackgroundImage:[UIImage imageNamed:@"aliefu_add"] forState:UIControlStateNormal];
            [cell.btn_img addTarget:self action:@selector(choosePicture) forControlEvents:UIControlEventTouchUpInside];
        }
//        else if (indexPath.item == 6){
//
//            //隐藏
//            [cell.btn_img setHidden:YES];
//            [cell.delete_btn setHidden:YES];
//            [cell.btn_img setHidden:YES];
//        }
        else{
            if (self.pictureArr.count>0) {
//                if (self.pictureArr.count > 5) {
//                    [self.pictureArr insertObject:@"" atIndex:6];
//                }
                  [cell.btn_img setBackgroundImage:self.pictureArr[indexPath.row - 2] forState:UIControlStateNormal];
                
              }
            [cell.btn_img setHidden:NO];
            cell.btn_lab.text = @"";
            [cell.delete_btn setHidden:NO];
        }
    }else{
        if (indexPath.item == 0) {
            [cell.btn_img setHidden:YES];
            [cell.delete_btn setHidden:YES];
            cell.btn_lab.text = @"作品视频";
        }else if (indexPath.item == 1){
            if (!self.coverImg){
                [cell.btn_img setHidden:NO];
                [cell.delete_btn setHidden:YES];
                cell.btn_lab.text = @"";
                [cell.btn_img setBackgroundImage:[UIImage imageNamed:@"aliefu_carema"] forState:UIControlStateNormal];
            }else{
                [cell.btn_img setHidden:NO];
                [cell.delete_btn setHidden:NO];
                cell.btn_lab.text = @"";
                [cell.btn_img setBackgroundImage:self.coverImg forState:UIControlStateNormal];
                cell.delete_btn.tag = 4000;
                [cell.delete_btn addTarget:self action:@selector(deleteVideo:) forControlEvents:UIControlEventTouchUpInside];
            }
            [cell.btn_img addTarget:self action:@selector(chooseVideo) forControlEvents:UIControlEventTouchUpInside];
        }
//        else{
//            if (!self.coverImg){
//                [cell.btn_img setHidden:YES];
//                [cell.delete_btn setHidden:YES];
//                cell.btn_lab.text = @"";
//            }else{
//                [cell.btn_img setHidden:NO];
//                [cell.delete_btn setHidden:NO];
//                cell.btn_lab.text = @"";
//                [cell.btn_img setBackgroundImage:self.coverImg forState:UIControlStateNormal];
//                [cell.delete_btn addTarget:self action:@selector(deleteVideo) forControlEvents:UIControlEventTouchUpInside];
//            }
//        }
    }
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0, 10, 0);
}

-(void)choosePicture{
    if ([self.delegate respondsToSelector:@selector(chooseWorkImg)]) {
        [self.delegate chooseWorkImg];
    }
}

-(void)deletePicture:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(deletePicture:)]) {
        [self.delegate deletePicture:sender];
    }
}

-(void)chooseVideo{
    if ([self.delegate respondsToSelector:@selector(chooseVideo)]) {
           [self.delegate chooseVideo];
       }
}

-(void)deleteVideo:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(deleteVideo:)]) {
        [self.delegate deleteVideo:sender];
    }
}

@end
